package leetcode.code1282;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import leetcode.IDebug;

public class Solution implements IDebug {

	public List<List<Integer>> groupThePeople(int[] groupSizes) {
		List<List<Integer>> ans = new ArrayList<>();
		Map<Integer, List<Integer>> lists = new HashMap<>();
		for (int i = 0; i < groupSizes.length; i++) {
			int cur = groupSizes[i];
			List<Integer> list = lists.getOrDefault(cur, new ArrayList<>());
			list.add(i);
			if (list.size() == cur) {
				ans.add(list);
				lists.remove(cur);
			}else {
				lists.put(cur, list);
			}
		}
		return ans;
	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
